<%@ page import="java.util.ArrayList" %>
<%@ page import="bean.Dep" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>
        系部信息查询页面
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="./css/x-admin.css" media="all">
    <script charset="utf-8">
        window.onload = function () {
            //全选
            let selectAll = document.getElementById("selectAll");
            let selects = document.getElementsByName("cbox");
            selectAll.onclick = function () {
                for (let i = 0; i < selects.length; i++) {
                    selects[i].checked = selectAll.checked;
                }
            };
        };
    </script>
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>系部信息</cite></a>
              <a><cite>系部信息查询</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:80%">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
                <label class="layui-form-label">日期范围</label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
                </div>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </div>
    </form>
    <%
        ArrayList<Dep> list = (ArrayList<Dep>) request.getAttribute("depList");
    %>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()">
            <i class="layui-icon">&#xe640;</i>批量删除
        </button>
        <button class="layui-btn layui-btn-danger" onclick="addInfo('添加','455','510')">
            <i class="layui-icon ">&#xe61f;</i>&nbsp;添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<%=list.size()%> 条</span></xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <label>
                    <input type="checkbox" id="selectAll" name="" value="">
                </label>
            </th>
            <th>系部编号</th>
            <th>系部名称</th>
            <th>联系电话</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr>
        <tr></tr>

        <c:forEach items="depList" var="s">
            <%for (Dep dep : list) {%>
            <tr>
                <td>
                    <label>
                        <input type="checkbox" value="<%=dep.getDno()%>" name="cbox">
                    </label>
                </td>
                <td><%=dep.getDno()%>
                </td>
                <td><%=dep.getDname()%>
                </td>
                <td><%=dep.getTel()%>
                </td>
                <td class="td-manage">
                    <button class="layui-btn layui-btn-warm" title="编辑"
                            onclick="admin_edit('编辑','<%=dep.getDno()%>','455','510')">
                        <i class="layui-icon">&#xe642;</i>
                    </button>
                    <button class="layui-btn" style="background-color: red"
                            onclick="admin_del(this,'<%=dep.getDno()%>')"
                            title="删除">
                        <i class="layui-icon">&#xe640;</i>
                    </button>
                </td>
            </tr>
            <%}%>
        </c:forEach>
        </tbody>
    </table>
</div>
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script src="./js/x-layui.js" charset="utf-8"></script>
<script>
    layui.use(['element', 'layer'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
    })

    //批量删除提交
    function delAll() {
        let objs = document.getElementsByName("cbox");
        let dno_list = [];
        for (let i = 0; i < objs.length; i++) {
            if (objs[i].checked) {
                dno_list.push(objs[i].value);
            }
        }
        let dno_list_str = dno_list.join(",");
        layer.confirm('确认要删除吗？', function (index) {
            layui.jquery.ajax({
                url: '/dep_batchDelete',
                type: 'post',
                data: {
                    "dno_list": dno_list_str
                },
                success: function (data) {
                    data = JSON.parse(data);
                    if (data.code === 200) {
                        layer.msg('删除成功', {icon: 1, time: 1000}, function () {
                            location.reload();
                        });
                    } else {
                        layer.msg('删除失败', {icon: 2, time: 1000});
                    }
                },
                error: function (data) {
                    layer.close(index);
                }
            });
        });
    }

    /*-删除*/
    function log_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }

    function admin_del(obj, dno) {
        layui.jquery.ajax({
            url: '/dep_delete',
            data: {
                "dno": dno,
                "flag": false
            },
            success: function (data) {
                data = JSON.parse(data);
                if (data.code === 200) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }
            }
        });
    }

    function admin_edit(title, dno, w, h) {
        let url = "/dep_change?dno=" + dno;
        x_admin_show(title, url, w, h);
    }

    /*添加*/
    function addInfo(title, w, h) {
        let url = './DepInfoAdd.html';
        x_admin_show("添加", url, w, h);
    }
</script>
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
</body>
</html>